package com.example.qmzy.ui.stories;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.qmzy.R;
import java.util.List;

public class StoriesAdapter extends RecyclerView.Adapter<StoriesAdapter.StoryViewHolder> {
    private List<MedicalStory> stories;

    public StoriesAdapter(List<MedicalStory> stories) {
        this.stories = stories;
    }

    @NonNull
    @Override
    public StoryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_story, parent, false);
        return new StoryViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull StoryViewHolder holder, int position) {
        MedicalStory story = stories.get(position);
        holder.titleTextView.setText(story.getTitle());
        holder.contentTextView.setText(story.getContent());
    }

    @Override
    public int getItemCount() {
        return stories.size();
    }

    static class StoryViewHolder extends RecyclerView.ViewHolder {
        TextView titleTextView;
        TextView contentTextView;

        StoryViewHolder(View itemView) {
            super(itemView);
            titleTextView = itemView.findViewById(R.id.story_title);
            contentTextView = itemView.findViewById(R.id.story_content);
        }
    }
} 